package com.github.hanlyjiang.androidtemplate.canvas;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.github.hanlyjiang.androidtemplate.R;

/**
 * Created by jianghanghang on 2016/11/23.
 */

public class CanvasTestView extends View {

    private Bitmap drawBitmap = null;

    public CanvasTestView(Context context) {
        super(context);
    }

    public CanvasTestView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public CanvasTestView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawColor(Color.WHITE);

        Paint paint = new Paint();
        paint.setColor(0x20FF00FF);

        canvas.translate(40, 40);
        canvas.drawRect(new RectF(0f, 0f, 200f, 200f), paint);

        paint.setColor(0x20FF00FF);
        canvas.translate(40, 40);
        canvas.drawRect(new RectF(0f, 0f, 400f, 400f), paint);

        canvas.rotate(45, 200f, 200f);
        canvas.drawRect(new RectF(0f, 0f, 400f, 400f), paint);

        if (drawBitmap == null) {
            drawBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        }


        canvas.rotate(-45, 200f, 200f);
        paint.setAlpha(255);
        canvas.drawBitmap(drawBitmap, 400f, 0f, paint);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();

    }
}
